//
//  BKLiuXueViewController.m
//  baokaodaxue
//
//  Created by dangyangyang on 15/6/1.
//  Copyright (c) 2015年 宏图教育. All rights reserved.
//

#import "BKLiuXueViewController.h"
#import "BKButton.h"
#import "BKResultOfLiuXueViewController.h"
#import "BKLiuXueViewModel.h"
#import "BKSearchField.h"
#import <MBProgressHUD.h>

@interface BKLiuXueViewController ()
@property (weak, nonatomic) IBOutlet BKButton *benke;
@property (weak, nonatomic) IBOutlet BKButton *zhuanke;
@property (weak, nonatomic) IBOutlet BKSearchField *guojia;
@property (weak, nonatomic) IBOutlet BKSearchField *dq;
@property (weak, nonatomic) IBOutlet BKSearchField *lx;
@property (weak, nonatomic) IBOutlet BKSearchField *kaoqu;

@end

@implementation BKLiuXueViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
   
  
    _benke.selected = YES;
    _zhuanke.selected = NO;
    
    _kaoqu.dataArray = @[
                                 @"不限",
                                 @"北京",
                                 @"天津",
                                 @"上海",
                                 @"重庆",
                                 @"河北",
                                 @"河南",
                                 @"山东",
                                 @"山西",
                                 @"安徽",
                                 @"江西",
                                 @"江苏",
                                 @"浙江",
                                 @"湖北",
                                 @"湖南",
                                 @"广东",
                                 @"广西",
                                 @"云南",
                                 @"贵州",
                                 @"四川",
                                 @"陕西",
                                 @"青海",
                                 @"宁夏",
                                 @"黑龙江",
                                 @"吉林",
                                 @"辽宁",
                                 @"西藏",
                                 @"新疆",
                                 @"内蒙古",
                                 @"海南",
                                 @"福建",
                                 @"甘肃"];
    _kaoqu.flag = 8011;
    _kaoqu.text = @"不限";
    
    __weak BKLiuXueViewController *weakSelf = self;
    [BKLiuXueViewModel countryWithSuccess:^(NSArray *dataArray) {
        NSMutableArray *array = [NSMutableArray arrayWithObject:@"不限"];
        [array addObjectsFromArray:dataArray];
        weakSelf.guojia.dataArray = array;
        weakSelf.guojia.flag = 8011;
        
        
        
    } failure:^(NSString *message) {
        
    }];
    
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    
    
    if ( [userDefaults objectForKey:@"dq"]) {
        _dq.text = [userDefaults objectForKey:@"dq"];
    }
    

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (IBAction)p_back:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];

}
- (IBAction)zhuanke:(id)sender {
    if ([sender isEqual:_benke]) {
        _benke.selected = YES;
        _zhuanke.selected= NO;
    }else{
    
        _zhuanke.selected = YES;
        _benke.selected = NO;
    }
    
    
}
- (IBAction)p_submit:(id)sender {
    
    __weak BKLiuXueViewController *weakSelf = self;
    NSString *bz;
    if (_benke.selected == YES) {
        bz = @"1";
    }else{
    
        bz=@"2";
    }
    
    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:hud];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.labelText = @"正在加载留学信息";
    [hud show:YES];
    
    [BKLiuXueViewModel liuxueWithbz:bz dq:_dq.text fw:_lx.text gj:_guojia.text success:^(NSArray *dataArray) {
        [hud hide:YES];
        [hud removeFromSuperview];
        BKResultOfLiuXueViewController *rsutl = [[BKResultOfLiuXueViewController alloc] initWithNibName:NSStringFromClass([BKResultOfLiuXueViewController class]) bundle:nil];
        rsutl.gjArray = weakSelf.guojia.dataArray;
        
        rsutl.dataArray = dataArray;
        [weakSelf.navigationController pushViewController:rsutl animated:YES];

    } failure:^(NSString *message) {
        [hud hide:YES];
    }];
    
    
    
}

@end
